package com.ecarx.camera.utils;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

import com.ecarx.camera.data.ThumbnailData;

public final class NaviUtils {

    private static final String GALLERY_PACKAGE_NAME = "ecarx.gallery";
    private static final String GALLERY_MAIN_ACTIVITY_NAME = "ecarx.gallery.GalleryMainActivity";

    private static final String GALLERY_ID_KEY = "GALLERY_ID";

    private static final String TAG = "NaviUtils";

    private NaviUtils() {
        throw new UnsupportedOperationException("u can't instantiate me...");
    }

    /**
     * todo 直接跳转至Gallery
     * @param context
     */
    public static void naviToGallery(Context context) {
        LogUtils.d(TAG, "naviToGallery");
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        ComponentName cn = new ComponentName(GALLERY_PACKAGE_NAME, GALLERY_MAIN_ACTIVITY_NAME);
        intent.setComponent(cn);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        try {
            context.startActivity(intent);
        } catch (Exception e) {
            LogUtils.d(TAG, "naviToGallery, e:" + e);
        }
    }

    /**
     * todo 跳转到Gallery大图预览页面
     * @param context
     * @param thumbnailData
     */
    public static void naviToGalleryPreview(Context context, ThumbnailData thumbnailData) {
        LogUtils.d(TAG, "naviToGalleryPreview, thumbnailData:" + thumbnailData);
        if (thumbnailData == null) {
            return;
        }
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        ComponentName cn = new ComponentName(GALLERY_PACKAGE_NAME, GALLERY_MAIN_ACTIVITY_NAME);
        intent.setComponent(cn);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        intent.putExtra(GALLERY_ID_KEY, thumbnailData.getGalleryId());
        try {
            context.startActivity(intent);
        } catch (Exception e) {
            LogUtils.d(TAG, "naviToGalleryPreview, e:" + e);
        }
    }
}
